//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "SurvivalProbabilityStructure.h"
using namespace Cephei::QL::Termstructures::Credit;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/DefaultProbabilityTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (boost::shared_ptr<QuantLib::SurvivalProbabilityStructure>& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
#ifdef HANDLE
	_phSurvivalProbabilityStructure = NULL;
#endif
	_ppSurvivalProbabilityStructure = &childNative;
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
}
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (QuantLib::SurvivalProbabilityStructure& childNative, Object^ owner) : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
#ifdef HANDLE
	_phSurvivalProbabilityStructure = NULL;
#endif
	_ppSurvivalProbabilityStructure = new boost::shared_ptr<QuantLib::SurvivalProbabilityStructure> (&childNative);
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
    _SurvivalProbabilityStructureOwner = owner;
    _DefaultProbabilityTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (CSurvivalProbabilityStructure^ copy) : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
#ifdef HANDLE
	_phSurvivalProbabilityStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSurvivalProbabilityStructure = new boost::shared_ptr<QuantLib::SurvivalProbabilityStructure> (copy->GetShared());
        _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
    }
}
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (PLATFORM::Type^ t) : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
#ifdef HANDLE
	_phSurvivalProbabilityStructure = NULL;
#endif
	if (!t->IsSubclassOf(CSurvivalProbabilityStructure::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (QuantLib::Handle<QuantLib::SurvivalProbabilityStructure>& childNative, Object^ owner)  : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
	_phSurvivalProbabilityStructure = &childNative;
	_ppSurvivalProbabilityStructure = &static_cast<boost::shared_ptr<QuantLib::SurvivalProbabilityStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
    _SurvivalProbabilityStructureOwner = owner;
}
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (QuantLib::Handle<QuantLib::SurvivalProbabilityStructure> childNative)  : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
	_phSurvivalProbabilityStructure = &childNative;
	_ppSurvivalProbabilityStructure = &static_cast<boost::shared_ptr<QuantLib::SurvivalProbabilityStructure>>(childNative.currentLink());
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::CSurvivalProbabilityStructure (QuantLib::SurvivalProbabilityStructure childNative)  : CDefaultProbabilityTermStructure(CSurvivalProbabilityStructure::typeid)
{
#ifdef HANDLE
	_phSurvivalProbabilityStructure = NULL;
#endif
	_ppSurvivalProbabilityStructure = new boost::shared_ptr<QuantLib::SurvivalProbabilityStructure> (new QuantLib::SurvivalProbabilityStructure (childNative));
    _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::DefaultProbabilityTermStructure> (*_ppSurvivalProbabilityStructure));
}
#endif

Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::~CSurvivalProbabilityStructure ()
{
    if (_ppSurvivalProbabilityStructure != NULL)
    {
	    delete _ppSurvivalProbabilityStructure;
        _ppSurvivalProbabilityStructure = NULL;
    }
}
Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::!CSurvivalProbabilityStructure ()
{
    if (_ppSurvivalProbabilityStructure != NULL)
    {
	    delete _ppSurvivalProbabilityStructure;
    }
}
QuantLib::SurvivalProbabilityStructure& Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::GetReference ()
{
    if (_ppSurvivalProbabilityStructure == NULL) throw REFNEW NativeNullException ();
	return **_ppSurvivalProbabilityStructure;
}
boost::shared_ptr<QuantLib::SurvivalProbabilityStructure>& Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::GetShared ()
{
    if (_ppSurvivalProbabilityStructure == NULL) throw REFNEW NativeNullException ();
	return *_ppSurvivalProbabilityStructure;
}
QuantLib::SurvivalProbabilityStructure* Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::GetPointer ()
{
    if (_ppSurvivalProbabilityStructure == NULL) throw REFNEW NativeNullException ();
	return &**_ppSurvivalProbabilityStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::SurvivalProbabilityStructure>& Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::GetHandle ()
{
	if (_phSurvivalProbabilityStructure == NULL)
	{
		_phSurvivalProbabilityStructure = new Handle<QuantLib::SurvivalProbabilityStructure> (*_ppSurvivalProbabilityStructure);
	}
	return *_phSurvivalProbabilityStructure;
}
#endif
bool Cephei::QL::Termstructures::Credit::CSurvivalProbabilityStructure::HasNative () 
{
	return (_ppSurvivalProbabilityStructure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

